﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FortuneHeavenCommon.ComMethod;
using FortuneHeavenCommon.DataMap;
using System.Data.SqlClient;

namespace FortuneHeavan.Game.DAL
{
    public class cftt_netpayDAL : UserDBBase
    {
    
        public List<cftt_netpay> GetList(int page, int size, string username)
        {
            if (string.IsNullOrEmpty(username) || username.Trim() == "")
            {
                string sql = @"SELECT * FROM (select  A.ID AS UserID, [id],[createdate],[username],[je],[lsh],[status] ,ROW_NUMBER() OVER(ORDER BY A.ID DESC) ROW   
from  dbo.cftt_netpay A  left join dbo.AccountsInfo B  on A.username = B.Accounts
 ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<cftt_netpay> list = Query<cftt_netpay>(sql,  new SqlParameter("@p0", size * (page - 1) + 1), new SqlParameter("@p1",size * page));
                return list;
            }
            else
            {
                string sql = @"SELECT * FROM (select  A.ID AS UserID, [id],[createdate],[username],[je],[lsh],[status] ,ROW_NUMBER() OVER(ORDER BY A.ID DESC) ROW   
from  dbo.cftt_netpay A  left join dbo.AccountsInfo B  on A.username = B.Accounts WHERE A.username = @usrname
 ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<cftt_netpay> list = Query<cftt_netpay>(sql, new SqlParameter("@usrname", username), new SqlParameter("@p0", size * (page - 1) + 1), new SqlParameter("@p1", size * page));
                return list;
            }
        }
        public int GetTotalSize(string username)
        {
            if (!string.IsNullOrEmpty(username) && username.Trim() != "")
            {
                string sql = @"select count(id) from cftt_netpay where rderID =@p0";
                return RunSQL(sql, new SqlParameter("@p0", username));
            }
            else
            {
                string sql = @"select count(id) from cftt_netpay";
                return RunSQL(sql);
            }
        }
    }
}
